package com.student_exam_system.dao;

import com.student_exam_system.pojo.Score;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ScoreMapper {
    /**添加一个Score
     * @param score 传入score类
     * @return int
     */
    int addScore(Score score);
    /**根据id删除一个Score
     * @param id 传入id
     * @return int
     */
    int deleteScoreById(int id);

    /**更新Score
     * @param score 传入score类
     * @return int
     */
    int updateScore(Score score);
    /**根据id查询,返回一个Score
     * @param id 传入id
     * @return int
     */
    Score queryScoreById(int id);
    /**查询全部Score,返回list集合
     * @return List<Score>
     */
    List<Score> queryAllScore();

    /**
     * 查看本班级的学生成绩情况【这里暂时考虑一个教师只教一个班】
     * @param classId  班级id
     * @param paperId 试卷id
     * @return  各个学生的成绩情况【按照成绩从高到低】
     */
    @Select("select * from exam.student_score where studentPaperId = #{paperId} and classId= #{classId} order by studentMark desc")
    @Results({
            @Result(column = "studentId",property = "user.userId"),
            @Result(column = "studentMark",property = "scoreMark"),
            @Result(column = "studentClass",property = "userClass.className"),
            @Result(column = "classId",property = "userClass.classId"),
            @Result(column = "studentPaperName",property = "paper.paperName"),
            @Result(column = "studentPaperId",property = "paper.paperId")
    })
    List<Score> studentScore(@Param("classId")int classId,@Param("paperId") int paperId);



    /**
     * 参加此次考试的所有班级的成绩情况【以平均分为标准】
     * @param paperId  试卷id
     * @param classId  班级id
     * @return  list集合的成绩对象
     */
    @Select("select ROUND(AVG(studentMark) ,3) as averageMark ,studentClass,studentPaperName from exam.student_score where classId= #{classId} and studentPaperId=#{paperId}")
    @Results({
            @Result(column = "average",property = "average"),
            @Result(column = "studentClass" ,property = "userClass.className"),
            @Result(column = "studentPaperName",property = "paper.paperName"),
    })
    List<Score> classScore(@Param("paperId")int paperId,@Param("classId")int classId);

    /**
     * 查找参加了这次考试的所有班级
     * @param paperId  试卷id
     * @return list集合的班级id
     */
    @Select("select classId from exam.student_score where studentPaperId= #{paperId}")
    List<Integer> partOrNotIds(int paperId);


}
